package com.zoo.diannaopeijian.service.impl;

import com.zoo.diannaopeijian.common.page.Page;
import com.zoo.diannaopeijian.common.util.CheckUtil;
import com.zoo.diannaopeijian.domain.Staff;
import com.zoo.diannaopeijian.mapper.StaffMapper;
import com.zoo.diannaopeijian.service.StaffService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 员工服务实现类
 */
@Service
public class StaffServiceImpl implements StaffService {
    @Resource
    private StaffMapper staffMapper;

    @Override
    public List<Staff> getStaff(Staff staff) {
        return staffMapper.select(staff);
    }

    @Override
    public List<Staff> getStaffWithPage(Page page, Staff staff) {
        if (page != null) {
            page.onPage();
        }

        return getStaff(staff);
    }

    @Override
    public List<Staff> getFuzzyStaff(Staff staff) {
        return staffMapper.selectFuzzyStaff(staff);
    }

    @Override
    public List<Staff> getFuzzyStaffWithPage(Page page, Staff staff) {
        if (page != null) {
            page.onPage();
        }

        return getFuzzyStaff(staff);
    }

    @Override
    public boolean addStaff(Staff staff) {
        if (CheckUtil.allNullBeanCheck(staff)) {
            return true;
        }
        return staffMapper.insertSelective(staff) == 1;
    }

    @Override
    public boolean deleteStaff(Integer staffId) {
        if (staffId == null) {
            throw new NullPointerException();
        }
        return staffMapper.deleteByPrimaryKey(staffId) == 1;
    }

    @Override
    public boolean updateStaff(Staff staff) {
        if (CheckUtil.allNullBeanCheck(staff)) {
            return true;
        }
        return staffMapper.updateByPrimaryKeySelective(staff) == 1;
    }

    @Override
    public String getStaffSaltById(Integer staffId) {
        if (staffId == null) {
            throw new NullPointerException();
        }
        return staffMapper.getStaffSaltById(staffId);
    }

    /**
     * 根据id获取员工
     *
     * @param staffId
     * @return
     */
    @Override
    public Staff getStaffById(Integer staffId) {
        return staffMapper.selectByPrimaryKey(staffId);
    }
}
